package livesun.justiceeternal.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.List;

import livesun.justiceeternal.R;
import livesun.justiceeternal.view.BadgeView;
import livesun.justiceeternal.view.adapter.BaseAdapter;
import livesun.justiceeternal.view.adapter.ViewHolder;

/**
 * 类描述：谱子列表
 * 创建人：livesun
 * 创建时间：2018/1/4.
 * 修改人：
 * 修改时间：
 * github：https://github.com/livesun
 */
public class ScoreListAdapter extends BaseAdapter<ItemsBean> {
    private Context mContext;

    public ScoreListAdapter(Context context) {
        super(context, R.layout.score_item_list);
        mContext = context;
    }

    @Override
    protected void bindData(ViewHolder holder, ItemsBean item) {
        TextView title=holder.getView(R.id.title);
        LinearLayout container=holder.getView(R.id.container);
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        layoutParams.setMargins(10,0,0,0);
        container.removeAllViews();

        title.setText(item.getTitle());
        container.addView(title);


        List<ScoreBean.LabelsBean> labels =
                item.getLabels();
        if(labels!=null){
            int size = labels.size();
            for(int i=0;i<size;i++){
                BadgeView badgeView=new BadgeView(mContext);
                badgeView.setText(labels.get(i).getName());
                badgeView.setBadgeBackgroundColor(Color.parseColor("#"+labels.get(i).getColor()));
                badgeView.setLayoutParams(layoutParams);
                badgeView.setTextSize(12);
                badgeView.setTextColor(Color.parseColor("#232323"));
                container.addView(badgeView);
            }
        }
    }
}
